using System;
using System.Collections;
using System.Collections.Generic;
using System.Xml;
using EditorExtensions;
using UnityEditor;
using UnityEngine;

namespace EditorFrameWork
{
    [CustomEditorWindow(7)]
    public class XMLGUIExmple : EditorWindow
    {
        private const string XMLFilePath = "Assets/EditorFrameWork/Example/7.XMLGUI/Editor/GUIExmple.xml";

        private string m_XMLlContent;

        private XMLGUI m_Xmlgui;

        private void OnEnable()
        {
            var xmlFileAsset = AssetDatabase.LoadAssetAtPath<TextAsset>(XMLFilePath);
            m_XMLlContent = xmlFileAsset.text;
            m_Xmlgui = new XMLGUI();
            m_Xmlgui.ReadXML(m_XMLlContent);
            m_Xmlgui.GetGUIBaseById<XMLGUILayoutButton>("loginButton").OnClick += () =>
            {
                Debug.Log("loginButton click!!");
                m_Xmlgui.GetGUIBaseById<XMLGUILayoutLabel>("label1").Text = "1";
                m_Xmlgui.GetGUIBaseById<XMLGUILayoutLabel>("label2").Text = "2";
                m_Xmlgui.GetGUIBaseById<XMLGUILayoutLabel>("label3").Text = "3";
            };
        }

        private void OnGUI()
        {
            m_Xmlgui.Draw();
        }
    }
}